//
//  QBBaseMainVC.m
//  Doctor
//
//  Created by 阳光 on 16/9/7.
//  Copyright © 2016年 阳光. All rights reserved.
//

#import "QBBaseMainVC.h"

@interface QBBaseMainVC ()

@property(nonatomic,strong)UIImageView *navBarHairlineImageView;;

@end

@implementation QBBaseMainVC

-(void)viewDidLoad
{
    [super viewDidLoad];
    
    // 左侧menu
    self.navigationItem.leftBarButtonItem=[UIBarButtonItem initWithNormalImage:@"menu" target:self action:@selector(menuEvent)];
    
    self.view.backgroundColor=MAIN_BACK_COLOR;
    
    [self ShowHiddenGrayColorLineImageViewOnNavigationBar];
}

// 使导航栏下面的一条黑线颜色变淡
-(void)ShowHiddenGrayColorLineImageViewOnNavigationBar
{
    NSArray *listArr = self.navigationController.navigationBar.subviews;
    for (UIView *obj in listArr) {
        if ([obj isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) {
            
            for (UIView *subView in obj.subviews)
            {
                if ([subView isKindOfClass:[UIImageView class]])
                {
                    UIImageView *hiddenImageView=(UIImageView *)subView;
                    hiddenImageView.hidden=NO;
                    hiddenImageView.alpha=.3;
                }
            }
        }
    }
}


-(void)menuEvent
{
    // 添加遮盖,拦截用户操作
    _coverBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    _coverBtn.frame=self.navigationController.view.bounds;
    _coverBtn.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:.5];
    [_coverBtn addTarget:self action:@selector(coverClick) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationController.view addSubview:_coverBtn];
    
    // 缩放比例
    CGFloat zoomScale = 1;
    // X移动距离
    CGFloat moveX=APPW*2/3;
    [UIView animateWithDuration:.2 animations:^{
        
        CGAffineTransform transform=CGAffineTransformMakeScale(zoomScale,zoomScale);
        // 先缩放在位移会使位移缩水,正常需要moveX/zoomScale 才是正常的比例,这里感觉宽度还好就省略此步
        self.navigationController.view.transform=CGAffineTransformTranslate(transform,moveX,0);
        //将状态改成已经缩放
        self.isScale = YES;
    }];
}

// cover点击
- (void)coverClick
{
    [UIView animateWithDuration:.2 animations:^{
        self.navigationController.view.transform=CGAffineTransformIdentity;
    } completion:^(BOOL finished){
        [self.coverBtn removeFromSuperview];
        self.coverBtn=nil;
        self.isScale=NO;
        // 当遮盖按钮被销毁时调用
        if (_coverDidRomove) {
            _coverDidRomove();
        }
    }];
}



@end
